package com.itheima.app.manager.pmsManager;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.itheima.commons.Code;
import com.itheima.commons.PageBean;
import com.itheima.commons.R;
import com.itheima.domain.db.pms.PmsProductAttribute;
import com.itheima.domain.db.pms.PmsProductCategoryAttributeRelation;
import com.itheima.exception.BusinessException;
import com.itheima.service.pmsService.ProductAttributeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yin
 * @date 2022/10/13 16:08
 */

@Component
public class ProductAttributeManager {

    @DubboReference
    ProductAttributeService productAttributeService;

    public R addProductAttribute(PmsProductAttribute pmsProductAttribute) {

        productAttributeService.addProductAttribute(pmsProductAttribute);
        return new R(Code.SUCCESS, "新增商品属性成功");
    }

    public R deleteProductAttribute(Integer[] ids) {
        productAttributeService.deleteProductAttribute(ids);
        return new R(Code.SUCCESS, "删除成功");
    }

    public PageBean listCid(Integer cid, Integer pageNum, Integer pageSize, Integer type) {
        PageBean result = productAttributeService.listCid(cid,pageNum,pageSize,type);
        return result;

    }

    public R updateProductAttribute(Integer id, PmsProductAttribute pmsProductAttribute) {

        if (ObjectUtils.isEmpty(id)) {
            throw new BusinessException("id为空");
        }
        productAttributeService.updateProductAttribute(id, pmsProductAttribute);
        return new R(Code.SUCCESS, "修改成功");
    }

    public R getById(Integer productCategoryId) {

        List<PmsProductCategoryAttributeRelation> ppcar =  productAttributeService.getById(productCategoryId);
        return R.ok(ppcar);
    }

    public R getProductAttrById(Integer id) {
        PmsProductAttribute pmsProductAttribute = productAttributeService.getProductAttrById(id);

        return R.ok(pmsProductAttribute);
    }
}
